import java.util.ArrayList;
import java.util.Collections;

public class LoserDriver {

	public static void main(String[] args) {
		String [] classList = {"Fred", "Barney", "Wilma", "Betty" };
		ArrayList<Loser> allLosers = new ArrayList<Loser>();
		
		// Initialize the briber list from a class list
		
		for(String person : classList) {
			allLosers.add(new Loser(person, 170));
		}
		
		// Start everyone out with the same loss
		
		for(Loser who : allLosers) {
			int currentWeight = who.getCurrentWeight();
			who.setCurrentWeight(currentWeight - 2);
		}
		
		// See if we have all the people with their initial weight loss
		
		System.out.println("After initial weight loss");
		
		for(Loser who : allLosers) {
			System.out.println("  " + who);
		}
		
		// Retrieve several people off the list and give them weight loss
		
		Loser	person;
		int		position;
		
		position = allLosers.indexOf(new Loser("Barney", 0));
		person = allLosers.get(position);
		person.setCurrentWeight(person.getCurrentWeight() - 5);
		
		position = allLosers.indexOf(new Loser("Wilma", 0));
		person = allLosers.get(position);
		person.setCurrentWeight(person.getCurrentWeight() - 20);
		
		Loser biggestLoser = Collections.max(allLosers);
		System.out.println("Biggest loser is: " + biggestLoser);
		
		// Sort the list and print it
		
		Collections.sort(allLosers);
		
		System.out.println("Sorted List is:");
		
		for(Loser who : allLosers) {
			System.out.println("  " + who);
		}
		
		// Find the smallest the hard way
		
		Loser currentSmallest = allLosers.get(0);
		for(int i = 1; i < allLosers.size(); i++) {
			Loser nextFromList = allLosers.get(i);
			if(nextFromList.compareTo(currentSmallest) < 0) {
				currentSmallest = nextFromList;
			}
		}
		
		System.out.println("Smallest via our work is " + currentSmallest.getName());
		
		// Get the smallest loser, remove them from the list
		// and print smallest and remaining list.
		// Collections.min is the shortcut for our code above.
		
		Loser smallestLoser = Collections.min(allLosers);
		allLosers.remove(smallestLoser);
		
		System.out.println("Smallest loser is: " + 
				smallestLoser.getName() +
				" with a weight loss of: " + 
				(smallestLoser.getStartWeight() - smallestLoser.getCurrentWeight())
				);
		
		System.out.println("Remaining losers are: ");
		for(Loser who : allLosers) {
			System.out.println(who.getName() +
					" " + who.getCurrentWeight() +
					" " + who.getWeightDifference());
		}
	}

}
